package com.test.languagetest;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;

import com.pojo.Product;

public class HibernateTestSQL {

	
	public static void main(String[] args) {
		
		// 使用session的createSQLQuery方法执行标准的sql
		SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
		Session session = sessionFactory.openSession();
		session.beginTransaction();
		
		String name = "phone";
		String sql = "select * from product_ p where p.name like '%" + name + "%'";
		
		Query query = session.createSQLQuery(sql);
		List<Object []> list = query.list();
		for(Object[] os : list) {
			
			for(Object filed : os) {
				System.out.print(filed+"\t");
			}
			System.out.println();
		}
		
		session.getTransaction().commit();
		session.close();
		sessionFactory.close();
		
	}
}
